package com.tim.wicket.examples;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormSubmitBehavior;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.PropertyModel;

public class AjaxExamplePage extends WebPage {
	
     private Form<HomePage> form;
     private TextField<String> textField;
     private Label message;
     private String enterSomething = "";

	public AjaxExamplePage() {
        form = new Form<HomePage>("defaultajaximplmentationform");
          add(form);
          textField = new TextField<String>("enterSomething", new PropertyModel<String>(this, "enterSomething")); 
          textField.add(new AjaxFormSubmitBehavior("onkeyup") {
  
              @Override
              protected void onSubmit(AjaxRequestTarget target) {
                  // do something meaningful here like updating the database
                  target.addComponent(message);
              }
  
              @Override
              protected void onError(AjaxRequestTarget target) {
                  throw new UnsupportedOperationException("Not supported yet.");
              }
          });
          form.add(textField);
          message = new Label("message", new PropertyModel<String>(this, "enterSomething"));
          message.setOutputMarkupId(true);
          add(message);
	}

}
